import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Button',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: ListPage(),
    );
  }
}

class ListPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //定义文本样式
    List _data = [
      {"id":1,"name":"iphone"},
      {"id":2,"name":"xiaomi"},
      {"id":3,"name":"huawei"},
      {"id":4,"name":"oppo"}
    ];
    return Scaffold(
      appBar: AppBar(
        title: Text("列表页"),
      ),
      body: Container(
        height: 400,
        child: ListView.builder(
          itemCount: _data.length,
          itemBuilder: (context,index){
            return new ListTile(
              title: Text(_data[index]["name"]),
              onTap: () async{
                String result = await Navigator.push(context, new MaterialPageRoute(builder: (context) => new DetailPage(_data[index]["id"], _data[index]["name"])));
                print(result);
                },
            );
        }),
      )
    );
  }

}


class DetailPage extends StatelessWidget {

  //构造函数
  int goods_id;
  String good_name;
  DetailPage(this.goods_id,this.good_name);


  @override
  Widget build(BuildContext context) {
    //定义文本样式

    return Scaffold(
      appBar: AppBar(
        title: Text("详情页面"),
      ),
      body: Column(
        children: <Widget>[
          Text(this.goods_id.toString()),
          Text(this.good_name),
          FlatButton(
            child: Text("返回"),
            color: Colors.red,
            onPressed: (){
              Navigator.pop(context, "第二个页面的返回值："+this.good_name);
            },
          )
        ],
      ),
    );
  }

}